import { Service } from "~/core/service";
import { NetService } from "~/util/net.service";
import { Inject, Debounce } from "~/core/decorator";
import { serviceManage } from "~/config/server";

export class RoleService extends Service {

  @Inject(NetService)
  private netService: NetService;

  /**
    * 新增角色
    */
  createRole(data) {
    return this.netService.send({
      server: serviceManage.roleController.createRole,
      data: {
        roleName: data.roleName,
        remark: data.remark
      }
    })
  }

  /**
   * 修改角色
   */
  updateRole(data) {
    return this.netService.send({
      server: serviceManage.roleController.updateRole,
      data: {
        id: data.id,
        roleName: data.roleName,
        remark: data.remark
      }
    })
  }

  /**
   * 删除角色
   */
  deleteRole(roleId) {
    return this.netService.send({
      server: serviceManage.roleController.deleteRole,
      append: roleId
    })
  }

  /**
   * 分页查询角色
   */
  findRoleListByPage(data, page) {
    return this.netService.send({
      server: serviceManage.roleController.findRoleListByPage,
      data: {
        roleName: data.roleName
      },
      page
    })
  }

  /**
   * 根据角色ID分页查询用户列表
   */
  queryUserListByRoleId(roleId, page) {
    return this.netService.send({
      server: serviceManage.roleController.queryUserListByRoleId,
      append: roleId,
      page
    })
  }

  /**
   * 查询角色可选资源，标识出已选中的
   */
  findRoleResourceList(roleId) {
    return this.netService.send({
      server: serviceManage.roleController.findRoleResourceList,
      append: roleId
    })
  }

  /**
   * 角色分配资源
   */
  assignResourceToRole(data) {
    return this.netService.send({
      server: serviceManage.roleController.assignResourceToRole,
      data: {
        roleId: data.roleId,
        resourceId: data.resourceId
      }
    })
  }
}